#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Service;
using System.Collections;
using Agresso.Interface.Layer.Domain;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class FindInterfaceHistoryForm : Form
    {
        string m_type = "";
        CommissionInvoiceService m_CommissionInvoiceService = new CommissionInvoiceService();

        public FindInterfaceHistoryForm(string type)
        {
            InitializeComponent();
            comboBoxTrType.Items.Add("SB");
            comboBoxTrType.Items.Add("SE");
            comboBoxTrType.Items.Add("SA");
            comboBoxTrType.Items.Add("SH");
            comboBoxTrType.Items.Add("SC");
            comboBoxTrType.Text = type;
        }
        private void FindCustomerForm_Load(object sender, EventArgs e)
        {
            textBoxInvoice.Focus();
        }
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            //if (textBoxInvoice.Text == "") { textBoxInvoice.Focus(); return; }
            IList result = m_CommissionInvoiceService.GetInterfacedTransaction(textBoxInvoice.Text.Trim(), comboBoxTrType.Text.Trim());
            listViewResult.Items.Clear();
            if (result.Count == 0)
            {
                ListViewItem item = listViewResult.Items.Add("");
                item.SubItems.Add("Nothing found. " + DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss"));
                statusBar1.Text = "Found : 0 item(s)";
            }
            else
            {
                foreach (InterfacedBatch asu in result)
                {
                    ListViewItem item = listViewResult.Items.Add(asu.invoice_number);
                    item.SubItems.Add(asu.batch_id);
                    item.SubItems.Add(asu.pickup_date.ToString("dd-MMM-yyyy HH:mm"));
                    item.Tag = asu;
                }
                statusBar1.Text = "Found : "+result.Count + " item(s)";
            }
        }

        private void listViewResult_DoubleClick(object sender, EventArgs e)
        {
            //if(listViewResult.SelectedItem==null)return;
            //if(listViewResult.SelectedItem.Tag==null)return;
            //asuheader acu = (asuheader)listViewResult.SelectedItem.Tag;
            //m_parentForm.UpdateAgressoSupplier(acu);
            //this.Close();
        }
        private void textBoxName_EnterKeyDown(object objSender, KeyEventArgs objArgs)
        {
            buttonSearch_Click(objSender, null);
        }

        private void comboBoxTrType_KeyDown(object objSender, KeyEventArgs objArgs)
        {
            if (objArgs.KeyCode == Keys.Enter)
                buttonSearch_Click(objSender, null);
        }
    }
}